package com.qujia.markert.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.enums.BusinessType;
import com.qujia.markert.domain.ReductionRules;
import com.qujia.markert.service.IReductionRulesService;
import com.qujia.common.utils.poi.ExcelUtil;
import com.qujia.common.core.page.TableDataInfo;

/**
 * 立减活动规则Controller
 * 
 * @author qujia
 * @date 2021-11-03
 */
@RestController
@RequestMapping("/market/reductionRules")
public class ReductionRulesController extends BaseController
{
    @Autowired
    private IReductionRulesService reductionRulesService;

    /**
     * 查询立减活动规则列表
     */
    @PreAuthorize("@ss.hasPermi('market:reductionRules:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReductionRules reductionRules)
    {
        startPage();
        List<ReductionRules> list = reductionRulesService.selectReductionRulesList(reductionRules);
        return getDataTable(list);
    }

    /**
     * 导出立减活动规则列表
     */
    @PreAuthorize("@ss.hasPermi('market:reductionRules:export')")
    @Log(title = "立减活动规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReductionRules reductionRules)
    {
        List<ReductionRules> list = reductionRulesService.selectReductionRulesList(reductionRules);
        ExcelUtil<ReductionRules> util = new ExcelUtil<ReductionRules>(ReductionRules.class);
        return util.exportExcel(list, "reductionRules");
    }

    /**
     * 获取立减活动规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:reductionRules:query')")
    @GetMapping(value = "/{rulesId}")
    public AjaxResult getInfo(@PathVariable("rulesId") Long rulesId)
    {
        return AjaxResult.success(reductionRulesService.selectReductionRulesById(rulesId));
    }

    /**
     * 新增立减活动规则
     */
    @PreAuthorize("@ss.hasPermi('market:reductionRules:add')")
    @Log(title = "立减活动规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReductionRules reductionRules)
    {
        return toAjax(reductionRulesService.insertReductionRules(reductionRules));
    }

    /**
     * 修改立减活动规则
     */
    @PreAuthorize("@ss.hasPermi('market:reductionRules:edit')")
    @Log(title = "立减活动规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReductionRules reductionRules)
    {
        return toAjax(reductionRulesService.updateReductionRules(reductionRules));
    }

    /**
     * 删除立减活动规则
     */
    @PreAuthorize("@ss.hasPermi('market:reductionRules:remove')")
    @Log(title = "立减活动规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rulesIds}")
    public AjaxResult remove(@PathVariable Long[] rulesIds)
    {
        return toAjax(reductionRulesService.deleteReductionRulesByIds(rulesIds));
    }
}
